#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
#include <algorithm>
using namespace std;
#define DEBUG
const int N=1e5+10;
using ll=long long;
int n, m;
ll a[N], b[N];
bool check(ll mid)
{
    ll mn=0;
    for(int i=1; i<=n; i++)
    {
        b[i]=a[i]-mid+b[i-1]; //计算减掉mid的前缀和
        if(i>=m)
        {
            mn=min(mn, b[i-m]);
            if(b[i]>=mn) return true; //b[i]>b[0...i-m]的最小值->i-m~i的累加和(减掉mid)
        }
    }
    return false;
}

void init()
{
    read(n), read(m);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]), a[i]*=1000;
}


void solve()
{
    init();
    ll l=1000, r=2000*1000;
    while(l<r)
    {
        ll mid=(l+r+1)/2;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    quickwrite(r);
    puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        // freopen("./out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
